package com.voucher.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ExtractIdUsingRegex {
    public static void main(String[] args) {
        String html = "<tr id=\"1234567890123456789012\">";
        html = removeSpacesAndNewlines(html);
        System.out.println(html);
        List<String> ids = extractIds(html);
        for (String id : ids) {
            System.out.println(id);
        }
    }


    public static String removeSpacesAndNewlines(String input) {
        // 去除空格和换行符
        return input.replaceAll("\\s+", "");
    }

    public static List<String> extractIds(String html) {
        List<String> ids = new ArrayList<>();
        // 定义正则表达式
        String regex = "<tr id=\"([^\"]{32})";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(html);

        // 查找所有匹配的 id
        while (matcher.find()) {
            ids.add(matcher.group(1));
        }
        return ids;
    }
}